﻿Module modControls
    Public Function Controls_ReturnByType(ByRef parentObject As Object, ByRef controlType As Type) As List(Of Control)

        Dim _control As Control
        Dim _recursion As List(Of Control)
        Dim _return As New List(Of Control)

        For Each _control In parentObject.Controls

            Dim _type As Type = _control.GetType()

            If _type Is controlType Then

                _return.Add(_control)

            End If

            If (_control.HasChildren) Then

                _recursion = Controls_ReturnByType(_control, controlType)

                For i As Integer = 0 To (_recursion.Count - 1)
                    _return.Add(_recursion(i))
                Next

            End If

        Next

        Return _return
    End Function
End Module